//testing
package prototype.santana;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *checking a branch.
 * @author Eric S
 */
public class SimulationManager {
    
    public static int state;
    final static int LOGIN_STATE = 0;
    final static int SCENARIO_STATE = 1;
    final static int SIMULATION_STATE = 2;
    final static int MAINTENANCE_STATE = 3;
    final static int EXIT_STATE= -1;
    
    

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SimulationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SimulationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SimulationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SimulationGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        
        
        
        SimulationManager manager = new SimulationManager();
        SimulationGUI mainGUI = new SimulationGUI(manager);
        LoginGUI loginDialog = new LoginGUI(null, true, manager);
        MaintenanceManagerGUI ProffesorGUIPrototype = new MaintenanceManagerGUI();
        ProffesorGUIPrototype.setVisible(false);
        ScenarioSelectionGUI scenarioSelectionGUIPrototype = new ScenarioSelectionGUI(manager);
        SimulationManager.state = LOGIN_STATE;
        while(SimulationManager.state!= EXIT_STATE){
            if(SimulationManager.state== LOGIN_STATE && scenarioSelectionGUIPrototype.isVisible() || (SimulationManager.state== LOGIN_STATE && mainGUI.isVisible())){
                scenarioSelectionGUIPrototype.setVisible(false);
                mainGUI.setVisible(false);
                if(!loginDialog.isVisible()){
                    JOptionPane.showMessageDialog(loginDialog,
                  "Welcome to Massbay General Hospital\n"
                + "Please Log in and follow the flow. ");
                    loginDialog.setVisible(true);
                }
            }
            else if(SimulationManager.state==LOGIN_STATE){
                if(!loginDialog.isVisible()){
                    JOptionPane.showMessageDialog(loginDialog,
                  "Welcome to Massbay General Hospital\n"
                + "Please Log in and follow the flow. ");
                loginDialog.setVisible(true);
                }
                mainGUI.setVisible(false);
                scenarioSelectionGUIPrototype.setVisible(false);
                ProffesorGUIPrototype.setVisible(false);
            }
            else if(SimulationManager.state== SCENARIO_STATE){
               if(!scenarioSelectionGUIPrototype.isVisible())
                scenarioSelectionGUIPrototype.setVisible(true);
                mainGUI.setVisible(false);
                loginDialog.setVisible(false);
                ProffesorGUIPrototype.setVisible(false);
            }
            else if(SimulationManager.state == SIMULATION_STATE){
                if(!mainGUI.isVisible())
                mainGUI.setVisible(true);
                loginDialog.setVisible(false);
                ProffesorGUIPrototype.setVisible(false);
                scenarioSelectionGUIPrototype.setVisible(false);
            }
            else if(SimulationManager.state == MAINTENANCE_STATE){
                if(!ProffesorGUIPrototype.isVisible())
                ProffesorGUIPrototype.setVisible(true);
                mainGUI.setVisible(false);
                loginDialog.setVisible(false);
                scenarioSelectionGUIPrototype.setVisible(false);
                
            }
            
            
            else if((!loginDialog.isVisible()&& SimulationManager.state==LOGIN_STATE))
                SimulationManager.state=EXIT_STATE;
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(SimulationManager.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
        System.exit(0);
        
        
        
    }
}
